<template>
  <div class="goc-page">
    <div class="components-container">
            <!-- 判题组件 -->
      <div class="component-section">
        <div class="component-wrapper">
          <GocJudge
            ref="judgeComponent"
            :problem="judgeProblem"
            :judgeMode="'loose'"
            :tolerance="2"
            :showDebugInfo="false"
            @judge-complete="onJudgeComplete"
            @code-submit="onCodeSubmit"
            @error="onJudgeError"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import GocJudge from '@/components/GocJudge.vue'
import logger from '../utils/logger.js'

export default {
  name: 'GocPage',
  components: {
    GocJudge
  },
  data() {
    return {
      judgeProblem: {
        id: '1',
        title: '绘制正方形',
        description: '使用GOC语言绘制一个边长为100的正方形',
        difficulty: '简单',
        timeLimit: 5000,
        memoryLimit: 128,
        starterCode: `int main() {
    // 在这里编写你的代码

    return 0;
}`,
        expectedCode: `int main() {
    cls();
    speed(8);
    fd(100);
    rt(90);
    fd(100);
    rt(90);
    fd(100);
    rt(90);
    fd(100);
    rt(90);
    return 0;
}`,
        testCases: [
          {
            input: '无输入',
            expectedOutput: '绘制一个边长为100的正方形',
            expectedTrace: [
              { cmd: 'cls', args: [] },
              { cmd: 'speed', args: [8] },
              { cmd: 'fd', args: [100] },
              { cmd: 'rt', args: [90] },
              { cmd: 'fd', args: [100] },
              { cmd: 'rt', args: [90] },
              { cmd: 'fd', args: [100] },
              { cmd: 'rt', args: [90] },
              { cmd: 'fd', args: [100] },
              { cmd: 'rt', args: [90] }
            ],
            score: 100
          }
        ]
      }
    }
  },
  methods: {
    // 判题完成回调
    onJudgeComplete(result) {
      logger.log('✅ 判题完成:', result)
      // 处理判题结果
    },
    
    // 代码提交回调
    onCodeSubmit(data) {
      logger.log('📝 代码提交数据:', data)
      // 发送到后端
    },
    
    // 判题错误回调
    onJudgeError(error) {
      logger.error('❌ 判题错误:', error)
      // 处理错误
    }
  },
  mounted() {
    logger.log('🎉 Goc 组件展示页面已加载')
  }
}
</script>

<style scoped>
.goc-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 1rem;
}

.components-container {
  max-width: 1200px;
  margin: 0 auto;
}

.component-section {
  background: white;
  border-radius: 12px;
  margin-bottom: 2rem;
  box-shadow: 0 8px 32px rgba(0,0,0,0.1);
  overflow: hidden;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.component-section:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 48px rgba(0,0,0,0.15);
}



.component-wrapper {
  padding: 1rem;
}





/* 响应式设计 */
@media (max-width: 768px) {
  .goc-page {
    padding: 1rem;
  }
  
  .page-title {
    font-size: 2rem;
  }
  
  .component-header {
    padding: 1rem;
    flex-direction: column;
    gap: 0.5rem;
    text-align: center;
  }
  
  .component-wrapper {
    padding: 1rem;
  }
}

/* 动画效果 */
.component-section {
  animation: slideInUp 0.6s ease;
}

@keyframes slideInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 为不同组件添加特定样式 */
.component-section:nth-child(1) { animation-delay: 0.1s; }
.component-section:nth-child(2) { animation-delay: 0.2s; }
.component-section:nth-child(3) { animation-delay: 0.3s; }
.component-section:nth-child(4) { animation-delay: 0.4s; }
.component-section:nth-child(5) { animation-delay: 0.5s; }
</style> 